<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>限时秒杀</title>
    <style>
        table,table tr td {
            border-collapse:collapse;
            border:1px solid #000;
        }
    </style>
    <script type="text/javascript" src="/jquery-3.5.1.min.js"></script>
    <script type="text/javascript" src="/util.js"></script>
    <script th:inline="javascript">
        $(function(){
            /**
             * 秒杀绑定
             */
            kill();
        });

        function kill(){
            $("#a_kill").click(function(){
                var $userId = [[${userId}]];
                var $secId = $("#td_seckillId").text();
                var url = "/seckill/kill?userId="+$userId+"&seckillId="+$secId+"";
                ajaxCall(url,function (result){
                    alert(result.message);
                    //跳转支付页面
                    window.location.href="/order/toPay?orderNo="+result.data+"&seckillId="+$secId;
                },function (e){
                    alert(e.responseJSON.message);
                });
            });
        }

    </script>
</head>
<body>
用户id：<span th:text="${userId}"></span><br>
<table border="1">
    <tr>
        <th>序号</th>
        <th>商品名称</th>
        <th>价格：元</th>
        <th>秒杀价格: 元</th>
        <th>秒杀数量</th>
        <th>秒杀</th>
    </tr>
    <tr th:each="sec,secStat : ${seclist}">
        <td id="td_seckillId" th:text="${sec.seckillId}"></td>
        <td th:text="${sec.goods.getName()}"></td>
        <td th:text="${sec.goods.getPrice()}" style="text-decoration: line-through"></td>
        <th th:text="${sec.getCurrentPrice()}"></th>
        <th th:text="${sec.goods.stock}"></th>
        <th><a id="a_kill" href="javascript:void(0)">秒杀</a></th>
    </tr>
</table>
</body>
</html>